home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 10 / 010.d81 / pps #22 < prev    next >
Text File  |  2022-08-26  |  4KB  |  259 lines

  1.  
  2.  PEEKs, POKEs, and SYSes -- Part 22
  3.           by Alan Gardner
  4.  
  5.  
  6. ======================================
  7.  
  8. Location: 1024-2023     Hex:$0400-07E7
  9. Official Label:VICSCN        Type: RAM
  10. Useful BASIC commands:      PEEK, POKE
  11.  
  12. --------------------------------------
  13.  
  14.   These 1000 locations are known
  15.  
  16. collectively as your text screen.
  17.  
  18. You are now 'looking' at all of these
  19.  
  20. locations.  Your text screen is like
  21.  
  22. a window into memory.  It just so
  23.  
  24. happens that your C-64 defaults to
  25.  
  26. locations 1024-2023.
  27.  
  28.   The locations start in the upper-
  29.  
  30. left hand corner and proceed across
  31.  
  32. the screen.  When you reach the right
  33.  
  34. side, you merely go back to the left
  35.  
  36. side, one line lower.  It's just like
  37.  
  38. reading a book.
  39.  
  40.   Now you might wonder what the
  41.  
  42. importance of all this is.  Well,
  43.  
  44. suppose you needed to scroll your
  45.  
  46. screen.  Sound easy enough?  Well, how
  47.  
  48. about scrolling left or right?  This
  49.  
  50. is where knowing about your text
  51.  
  52. screen comes in handy.
  53.  
  54.   Now lets take scrolling left first.
  55.  
  56. We want a routine to take information
  57.  
  58. and slide it to the left.  First of
  59.  
  60. all, we need to know that our screen
  61.  
  62. is 40 characters across and 25 lines
  63.  
  64. tall.  Let's draw a picture of a bit
  65.  
  66. of our text screen.
  67.  
  68.  
  69.  
  70.   !{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}!{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}!{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}!{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}!{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}!
  71.   !1024 !1025 !1026 !1027 !.... !
  72.   !     !     !     !     !     !
  73.   !{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}!{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}!{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}!{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}!{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}!
  74.   !1064 !1065 !1066 !1067 !.... !
  75.   !     !     !     !     !     !
  76.   {CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}{CBM-T}
  77.  
  78.  
  79. Now what we want to do is this:
  80.  
  81.   1.  Take what is in location 1024
  82.       off of the screen.
  83.  
  84.   2.  Move what is in location 1025
  85.       into location 1024.
  86.  
  87.   3.  Move what is in location 1026
  88.       into location 1025
  89.  
  90.   4.  Etc...
  91.  
  92.   5.  Move what is in location 1064
  93.       off of the screen.
  94.  
  95.   6.  Move what is in location 1065
  96.       into location 1064.
  97.  
  98.   7.  Move what is in location 1066
  99.       into location 1065
  100.  
  101.   8.  Etc.... Until we move what is
  102.       in location 2023 into location
  103.       2022.
  104.  
  105.  
  106. You might notice that if the location
  107.  
  108. is on the left side of the screen, we
  109.  
  110. move it off completely.  But what
  111.  
  112. about the locations on the far right
  113.  
  114. of the screen?  Well, we'll just fill
  115.  
  116. them with spaces.
  117.  
  118.  
  119.  Now that you're thoroughly confused..
  120.  
  121. There are many different ways to
  122.  
  123. approach this task.  Here is one of
  124.  
  125. them:
  126.  
  127.  
  128.   First set a variable equal to the
  129.  
  130. base address of our text screen.
  131.  
  132.  
  133. 10 BA=1024 : REM   base address
  134.  
  135.  
  136.   Next, we'll have to have two loops.
  137.  
  138. One loop is for going across the
  139.  
  140. screen, and the other loop is for
  141.  
  142. going down the screen.
  143.  
  144.  
  145. 20 FOR Y=0to24  : REM  down screen
  146. 30 FOR X=0to38  : REM  across screen
  147.  
  148.  
  149. You might have noticed that we are
  150.  
  151. only going across for 39 characters
  152.  
  153. (0-38 is 39 characters).  This is
  154.  
  155. because we want to store a space in
  156.  
  157. the right-most location on each line.
  158.  
  159.   Now a formula for calculating where
  160.  
  161. we are on the screen is:
  162.  
  163.  
  164.    ADDRESS=BA+40*Y+X
  165.  
  166.   Y is the number of lines down and
  167.  
  168. X is the number of spaces across.
  169.  
  170.  
  171. 40 ADDR=BA+40*Y+X : REM  where are we?
  172.  
  173.  
  174. Now that we know where we are, we
  175.  
  176. can find out what is there and then
  177.  
  178. put it in the right place.  Because
  179.  
  180. we are scrolling left, we want to
  181.  
  182. 'look ahead' at the next location to
  183.  
  184. find out what to put in the current
  185.  
  186. location  (make sense?).  Well, if
  187.  
  188. you're a bit confused, take another
  189.  
  190. look at the diagram way up at the
  191.  
  192. beginning, and then look at the 8
  193.  
  194. steps which we want to follow.  Now
  195.  
  196. when I say we want to move the
  197.  
  198. contents of the left-most locations
  199.  
  200. off the screen, this does not mean
  201.  
  202. that we have to pick them up and move
  203.  
  204. them.  Why not just move the right
  205.  
  206. thing into them?  Here is the rest
  207.  
  208. of the program with some more
  209.  
  210. description:
  211.  
  212.  
  213. 50 POKE ADDR, PEEK(ADDR+1)
  214. 60 NEXT X
  215. 70 POKE ADDR+1,32
  216. 80 NEXT Y
  217.  
  218.  
  219. Line 50 is the main step in our
  220.  
  221. program.  What it does is pick up what
  222.  
  223. is in one location and put it into
  224.  
  225. the location directly to the left of
  226.  
  227. it. For example, it takes out what
  228.  
  229. is in location 1025 and puts what
  230.  
  231. it finds into 1024.  This produces our
  232.  
  233. scroll left effect.  Line 70 is to put
  234.  
  235. a space in the right-most locations. 
  236.  
  237. A 32 is the ASCII value for a space.
  238.  
  239.   That's all there is to this small
  240.  
  241. scroll left program.  It works a
  242.  
  243. little slow, but that's the price
  244.  
  245. you pay for using BASIC.  You may
  246.  
  247. notice one small problem with this
  248.  
  249. routine.  If you have characters of
  250.  
  251. different colors on your screen, the
  252.  
  253. colors can really get messed up! 
  254.  
  255. Well....check out Part 23!
  256.  
  257.  
  258. ------- continued in Part 23 ---------
  259.